/* Calculates the collision state of two objects
 can be used to link two objects or reused to test multiple different objects
 */


class Collision_detector {

  boolean collision;

  Particle one;
  Particle two;

  float distance;

  float[] location = new float[2];

  Collision_detector() {
  } 

  void set_particle_one(Particle one) {
    this.one = one;
  }


  void set_particle_two(Particle two ) {
    this.two = two;
  }

  float get_distance() {
    collision_distance();
    return distance;
  }


  boolean is_collision(Particle two) {
    this.two = two; 
    return is_collision();
  }

  boolean is_collision(Particle one, Particle two) {
    this.one = one;
    this.two = two;
    return is_collision();
  }


  boolean is_collision() {
    collision_distance();
    collision = (distance < one.radius+two.radius)?true:false;
    distance = -1;
    return collision;
  }

  float[] get_location() {
    ////// calculate the point of impact of the last collision
    return location;
  }

  void collision_distance() {
    distance = sqrt(  sq(two.x_loc - one.x_loc) + sq(two.y_loc - one.y_loc));
  }
}

